/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package residentialdatabasemanagement;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Muoi'
 */
public class DanCu extends javax.swing.JFrame {
    DefaultTableModel model;
    public DanCu() {
        initComponents();
        model = (DefaultTableModel) tbl_DC.getModel();
        loadTableDC();
    }

    /**
     *
     */
    public void loadTableDC(){
        try {
            ConnectToSQL s = new ConnectToSQL();
            Connection conn = s.getConnectToMSSQL();
            Statement stm = conn.createStatement();
            ResultSet rs = stm.executeQuery("select DanCu.MaDanCu,DanCu.HoTen,DanCu.GioiTinh,DanCu.NgaySinh,DanCu.NgheNghiep,DanCu.QueQuan,DanCu.SoCMND,CanHo.MaCanHo,CanHo.CanHo,CanHo.ToaNha,CanHo.Tang from CanHo inner join DanCu on CanHo.MaCanHo=DanCu.MaCanHo");
            while(rs.next()){
            Vector data_row = new Vector();
            data_row.add(rs.getString(1));
            data_row.add(rs.getString(2));
            data_row.add(rs.getString(3));
            data_row.add(rs.getString(4));
            data_row.add(rs.getString(5));
            data_row.add(rs.getString(6));
            data_row.add(rs.getString(7));
            data_row.add(rs.getString(8));
            data_row.add(rs.getString(9));
            data_row.add(rs.getString(10));
            data_row.add(rs.getString(11));
            model.addRow(data_row);
            }
            tbl_DC.setModel(model);
        } 
        catch (SQLException ex) {
            Logger.getLogger(DanCu.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        }
        
    
        

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txt_timDC = new javax.swing.JTextField();
        cmd_timDC = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbl_DC = new javax.swing.JTable();
        cmd_themDC = new javax.swing.JButton();
        cmd_suaDC = new javax.swing.JButton();
        cmd_thoatDC = new javax.swing.JButton();
        cmd_xoaDC = new javax.swing.JButton();
        cmd_dauDC = new javax.swing.JButton();
        cmd_truocDC = new javax.swing.JButton();
        cmd_cuoiDC = new javax.swing.JButton();
        cmd_sauDC = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txt_maDC = new javax.swing.JTextField();
        txt_tenDC = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txt_gioiTinhDC = new javax.swing.JTextField();
        txt_ngaySinhDC = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_nghenghiepDC = new javax.swing.JTextField();
        txt_queQuanDanCu = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txt_CMND = new javax.swing.JTextField();
        txt_maCanHoDC = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txt_timDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N

        cmd_timDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_timDC.setText("Tìm kiếm");

        tbl_DC.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã Dân Cư", "Tên Dân Cư", "Giới Tính", "Ngày sinh", "Nghề nghiệp", "Quê quán", "Số CMND", "Mã Căn Hộ", "Căn hộ", "Tòa nhà", "Tầng"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tbl_DC.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbl_DCMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbl_DC);

        cmd_themDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_themDC.setText("Thêm");

        cmd_suaDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_suaDC.setText("Sửa");

        cmd_thoatDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_thoatDC.setForeground(new java.awt.Color(255, 0, 51));
        cmd_thoatDC.setText("Thoát");

        cmd_xoaDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_xoaDC.setText("Xóa");
        cmd_xoaDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmd_xoaDCActionPerformed(evt);
            }
        });

        cmd_dauDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_dauDC.setText("Đầu");
        cmd_dauDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmd_dauDCActionPerformed(evt);
            }
        });

        cmd_truocDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_truocDC.setText("Trước");

        cmd_cuoiDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_cuoiDC.setText("Cuối");

        cmd_sauDC.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        cmd_sauDC.setText("Sau");

        jLabel1.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("QUẢN LÝ DÂN CƯ");

        txt_maDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_maDCActionPerformed(evt);
            }
        });

        txt_tenDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_tenDCActionPerformed(evt);
            }
        });

        jLabel2.setText("Mã dân cư :");

        jLabel3.setText("Tên dân cư :");

        txt_gioiTinhDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_gioiTinhDCActionPerformed(evt);
            }
        });

        txt_ngaySinhDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_ngaySinhDCActionPerformed(evt);
            }
        });

        jLabel4.setText("Ngày sinh :");

        jLabel5.setText("Giới tính :");

        txt_nghenghiepDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_nghenghiepDCActionPerformed(evt);
            }
        });

        txt_queQuanDanCu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_queQuanDanCuActionPerformed(evt);
            }
        });

        jLabel6.setText("Quê quán : ");

        jLabel7.setText("Nghề nghiệp : ");

        txt_CMND.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_CMNDActionPerformed(evt);
            }
        });

        txt_maCanHoDC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_maCanHoDCActionPerformed(evt);
            }
        });

        jLabel8.setText("Mã căn hộ :");

        jLabel9.setText("Số CMND : ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(250, 250, 250)
                        .addComponent(txt_timDC, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cmd_timDC))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(306, 306, 306)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(201, 201, 201)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cmd_dauDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cmd_truocDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cmd_themDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30)
                                .addComponent(cmd_suaDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addComponent(cmd_xoaDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(cmd_thoatDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(cmd_sauDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cmd_cuoiDC, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(txt_CMND, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txt_maDC)
                                    .addComponent(txt_tenDC, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txt_gioiTinhDC)
                                    .addComponent(txt_ngaySinhDC, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txt_nghenghiepDC)
                                    .addComponent(txt_queQuanDanCu, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(txt_maCanHoDC, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(58, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 927, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_timDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmd_timDC))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txt_maDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txt_tenDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txt_gioiTinhDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txt_ngaySinhDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_nghenghiepDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_queQuanDanCu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_maCanHoDC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(txt_CMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmd_dauDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_cuoiDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_truocDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_sauDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmd_themDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_suaDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_xoaDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmd_thoatDC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txt_maDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_maDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_maDCActionPerformed

    private void txt_tenDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_tenDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_tenDCActionPerformed

    private void txt_gioiTinhDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_gioiTinhDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_gioiTinhDCActionPerformed

    private void txt_ngaySinhDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_ngaySinhDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_ngaySinhDCActionPerformed

    private void txt_nghenghiepDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_nghenghiepDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_nghenghiepDCActionPerformed

    private void txt_queQuanDanCuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_queQuanDanCuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_queQuanDanCuActionPerformed

    private void txt_CMNDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_CMNDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_CMNDActionPerformed

    private void txt_maCanHoDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_maCanHoDCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_maCanHoDCActionPerformed

    private void cmd_xoaDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmd_xoaDCActionPerformed
        try {
            ConnectToSQL s = new ConnectToSQL();
            Connection conn = s.getConnectToMSSQL();
            PreparedStatement pstm = conn.prepareStatement("DELETE from DanCu where MaDanCu=?");
            String NV = tbl_DC.getValueAt(tbl_DC.getSelectedRow(),1).toString();
            pstm.setString(1,NV);
            pstm.executeUpdate();
            
            txt_maDC.setText(null);
            txt_tenDC.setText(null);
            txt_gioiTinhDC.setText(null);
            txt_nghenghiepDC.setText(null);
            txt_queQuanDanCu.setText(null);
            txt_CMND.setText(null);
            txt_ngaySinhDC.setText(null);
            txt_maCanHoDC.setText(null);    
            model.removeRow(tbl_DC.getSelectedRow());
        } catch (SQLException ex) {
            Logger.getLogger(DanCu.class.getName()).log(Level.SEVERE, null, ex);
        }
                
                
        
    }//GEN-LAST:event_cmd_xoaDCActionPerformed

    private void tbl_DCMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbl_DCMouseClicked
        //System.out.println(tbl_DC.getSelectedRow());
        txt_maDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),0) );
        txt_tenDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),1) );
        txt_gioiTinhDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),2) );
        txt_ngaySinhDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),3) );
        txt_nghenghiepDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),4) );
        txt_queQuanDanCu.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),5) );
        txt_CMND.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),6) );
        txt_maCanHoDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),7) );
// TODO add your handling code here:
    }//GEN-LAST:event_tbl_DCMouseClicked

    private void cmd_dauDCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmd_dauDCActionPerformed
                  tbl_DC.setRowSelectionInterval(0,0);  // TODO add your handling code here:
                  txt_maDC.setText((String) tbl_DC.getValueAt(tbl_DC.getSelectedRow(),0) );
        txt_tenDC.setText((String) tbl_DC.getValueAt(0,1) );
        txt_gioiTinhDC.setText((String) tbl_DC.getValueAt(0,2) );
        txt_ngaySinhDC.setText((String) tbl_DC.getValueAt(0,3) );
        txt_nghenghiepDC.setText((String) tbl_DC.getValueAt(0,4) );
        txt_queQuanDanCu.setText((String) tbl_DC.getValueAt(0,5) );
        txt_CMND.setText((String) tbl_DC.getValueAt(0,6) );
        txt_maCanHoDC.setText((String) tbl_DC.getValueAt(0,7) );
    }//GEN-LAST:event_cmd_dauDCActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DanCu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DanCu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DanCu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DanCu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
              
                    new DanCu().setVisible(true);
             
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmd_cuoiDC;
    private javax.swing.JButton cmd_dauDC;
    private javax.swing.JButton cmd_sauDC;
    private javax.swing.JButton cmd_suaDC;
    private javax.swing.JButton cmd_themDC;
    private javax.swing.JButton cmd_thoatDC;
    private javax.swing.JButton cmd_timDC;
    private javax.swing.JButton cmd_truocDC;
    private javax.swing.JButton cmd_xoaDC;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbl_DC;
    private javax.swing.JTextField txt_CMND;
    private javax.swing.JTextField txt_gioiTinhDC;
    private javax.swing.JTextField txt_maCanHoDC;
    private javax.swing.JTextField txt_maDC;
    private javax.swing.JTextField txt_ngaySinhDC;
    private javax.swing.JTextField txt_nghenghiepDC;
    private javax.swing.JTextField txt_queQuanDanCu;
    private javax.swing.JTextField txt_tenDC;
    private javax.swing.JTextField txt_timDC;
    // End of variables declaration//GEN-END:variables
}
